from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Setting, DeskTop


# 本条用例依赖3800添加用户的用例
class PreTest_RK3568_Basic_Setting_3900(TestCase, Setting):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面
    # 测试步骤：
    # 1.进入桌面，点击设置-用户和帐号-当前登录（若无"新用户"需要先添加一个新用户）
    # 2.点击已添加的新用户，点击删除用户
    # 3.点击删除
    # 预期结果：
    # 1.可正常进入到当前登录界面
    # 2.点击已添加的新用户可正常弹出弹窗，点击删除用户可正常弹出删除确认的弹窗
    # 3.点击删除可以正常删除用户

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：进入桌面，点击设置-用户和帐号-当前登录（若无"新用户"需要先添加一个新用户）')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '用户和帐户')
        CommonOH.wait(self.Phone1, 1)
        Step('预期结果1：可正常进入到当前登录界面')
        CommonOH.checkIfTextExist(self.Phone1, '当前登录')
        CommonOH.checkIfTextExist(self.Phone1, 'test')
        CommonOH.touchByText(self.Phone1, '当前登录')
        CommonOH.wait(self.Phone1, 1)

        Step('步骤2：点击已添加的新用户，点击删除用户')
        CommonOH.touchByText(self.Phone1, '删除')
        CommonOH.wait(self.Phone1, 1)
        CommonOH.touchByText(self.Phone1, '删除', index=1)
        CommonOH.wait(self.Phone1, 5)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.forceStopAbility(self.Phone1, self.bundle_name)
        CommonOH.wait(self.Phone1, 2)
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '用户和帐户')
        CommonOH.wait(self.Phone1, 1)
        Step('预期结果3：点击删除可以正常删除用户')
        CommonOH.checkIfTextExist(self.Phone1, '当前登录')
        CommonOH.checkIfTextExist(self.Phone1, 'test', expect=False)

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
